package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/iot")
@RequiredArgsConstructor
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController {

    private final DeviceService deviceService;


    /**
     * 同步产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation("同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    /**
     * 获取产品列表
     * @return
     */
    @GetMapping("/allProduct")
    @ApiOperation("获取产品列表")
    public ResponseResult<List<ProductVo>> getProductList() {
        log.info("获取产品列表");
        List<ProductVo> productList = deviceService.getProductList();
        return ResponseResult.success(productList);
    }

    /**
     * 注册设备
     * @param deviceDto
     * @return
     */
    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto) {
        log.info("注册设备，参数：{}", deviceDto);
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 设备分页条件查询
     * @param devicePageQueryDto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        log.info("分页查询设备列表，参数：{}", devicePageQueryDto);
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 查询设备详细数据
     * @param request
     * @return
     */
    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详细数据")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request) {
        log.info("查询设备详细数据，参数：{}", request);
        DeviceVo deviceVo = deviceService.queryDeviceDetail(request);
        return ResponseResult.success(deviceVo);
    }

    /**
     * 查询指定设备的物模型运行状态
     * @param request
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult<List<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData >>
    QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        log.info("查询指定设备的物模型运行状态，参数：{}", request);
        QueryDevicePropertyStatusResponseBody.
        QueryDevicePropertyStatusResponseBodyData  data = deviceService.QueryDevicePropertyStatus(request);
        return ResponseResult.success(data);
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param request
     * @return
     */
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult<List<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData >>
    QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        log.info("查看指定产品的已发布物模型中的功能定义详情，参数：{}", request);
        QueryThingModelPublishedResponseBody.
        QueryThingModelPublishedResponseBodyData  data = deviceService.QueryThingModelPublished(request);
        return ResponseResult.success(data);
    }

    /**
     * 修改设备备注名称
     * @param deviceDto
     * @return
     */
    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备备注名称")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto) {
        log.info("修改设备备注名称，参数：{}", deviceDto);
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 删除设备
     * @param request
     * @return
     */
    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult DeleteDevice(@RequestBody DeleteDeviceRequest request) {
        log.info("删除设备,参数：{}", request);
        deviceService.deleteDevice(request);
        return ResponseResult.success();
    }
}
